﻿<%@ Page Title="" Language="C#" MasterPageFile="/Common/Master.master" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentForm" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentHtml" runat="Server">
    <div class="easyui-layout tableEdit" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false" id="validation" class="validationEngineContainer">
            <div class="z_wrap">
                <ul class="info">
                    <li>
                        <em class='l_name'>登录名称：</em>
                        <div class='r_con1'>
                            <input id='login_name' name='login_name' type='text' readonly="true" />
                        </div>
                    </li>

                    <li>
                        <label class="l_name">用户名：</label>
                        <div class="r_con1">
                            <input id='user_name' name='user_name' type='text' class="input-control validate[required]" />
                        </div>
                    </li>

                    <li>
                        <label class="l_name">性别：</label>
                        <div class="r_con1" id="tpfj">
                            <select id="Gender" name="Gender" class="input-control" style="width: 80px;">
                                <option value="男" selected="selected">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                    </li>

                    <li>
                        <label class="l_name">手机号：</label>
                        <div class="r_con1">
                            <input id='Mobile' name='Mobile' type='text' class="input-control validate[required,custom[phone]]" />
                        </div>
                    </li>


                    <li>
                        <label class="l_name">备注：</label>
                        <div class="r_con1">
                            <textarea id='Remark' name='Remark' style='height: 80px; width: 258px;'></textarea>
                        </div>
                    </li>

                    <li>
                        <label class="l_name">头像：</label>
                        <div class="r_con1">
                            <div id="filePicker" class="btn btn-block" style="float: left; margin-left: 10px; margin-top: 5px;">选择文件</div>
                            <img src="" id="imgs" style="float: left; margin-left: 10px; width: 100px; height: auto;" />
                        </div>

                        <div class="col-sm-4 " style="display: none;">
                            <input id='ImgUrl' name='ImgUrl' type='text' disabled class="input-control" />
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <div data-options="region:'south'" style="height: 35px; border-bottom: 0px; border-left: 0px; border-right: 0px;" class="edit_bottom">
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'" id="buttonOk">确 定</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$.layerClose(false);">取 消</a>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            jQuery('#validation').validationEngine();

            $("#buttonOk").click(function () {
                InsertOrUpdate();
            });
            DataBind();
        });

        function DataBind() {
            $.InvokeAjax("Login", "GetCahceByKey", {}, true, function (data) {
                var obj = $.StrToJson(data).Results;

                $.SetValue("login_name", obj.login_name);
                $.SetValue("user_name", obj.user_name);
                $.SetValue("ImgUrl", obj.ImgUrl);
                $("#imgs").attr("src", obj.ImgUrl);
                $.SetValue("Gender", obj.Gender);
                $.SetValue("Mobile", obj.Mobile);
                $.SetValue("Remark", obj.Remark);
            });
        }

        function InsertOrUpdate() {
            if (!$('#validation').validationEngine('validate')) { return false; }

            var obj = {};
            obj.ID = $.cookie("login_token");
            obj.user_name = $.GetValue("user_name");
            obj.ImgUrl = $.GetValue("ImgUrl");
            obj.Gender = $.GetValue("Gender");
            obj.Mobile = $.GetValue("Mobile");
            obj.Remark = $.GetValue("Remark");
            obj.LastVisit = $.JsonDateFy(obj.LastVisit);
            obj.AddTime = $.JsonDateFy(obj.AddTime);

            $.InvokeAjax("Login", "UpdateUserInfo", obj, true, function (data) {
                $.messager.alert('提示', '编辑资料成功！', 'info');
            });
        }
    </script>
    <script type="text/javascript">
        $(function () {
            // 初始化Web Uploader
            var uploader = WebUploader.create({
                duplicate: true, //同一个文件可以多次上传
                auto: true,// 自动上传。
                swf: '/Js/plugin/webuploader/Uploader.swf',// swf文件路径
                server: '/Common/Upload.ashx',// 文件接收服务端。
                pick: '#filePicker',// 选择文件的按钮。可选。

                // 只允许选择文件，可选。
                accept: {
                    title: '文件',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: '*/*'
                }
            });

            uploader.on("error", function (type) {
                if (type == "Q_TYPE_DENIED") {
                    layer.alert("上传文件格式不正确,可以上传 gif,jpg,jpeg,bmp,png格式");
                }
                //else if (type == "F_EXCEED_SIZE") {
                //    layer.alert("文件大小不能超过" + 5 + "M");
                //}
            });
            //文件上传成功
            uploader.on('uploadSuccess', function (file, ret) {
                $("#ImgUrl").val(ret.url);
                $("#imgs").attr("src", ret.url);
            });
        });
    </script>
</asp:Content>

